package com.da.lon.wang.xlg.util;

import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;

import com.da.lon.wang.xlg.constants.XLGConstants;

/* 定义一个倒计时的内部类 */
public class TimeCount extends CountDownTimer {

    private Handler vpHandler;

    public TimeCount(long millisInFuture, long countDownInterval, Handler vpHandler) {
        super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
        this.vpHandler = vpHandler;
    }

    @Override
    public void onFinish() {
        // 计时完毕时触发
//		Message message = new Message();
//		message.what = XLGConstants.TIMEDOWN;
//		message.obj = 0L;
//		vpHandler.sendMessage(message);

        Message obtain = Message.obtain(vpHandler, XLGConstants.TIMEDOWN, 0L);
        obtain.sendToTarget();
        LogUtils.v("计时完毕时触发");
    }

    @Override
    public void onTick(long millisUntilFinished) {
        // 计时过程显示
//		LogUtils.v(millisUntilFinished / 1000 + "秒");
//		vpHandler.removeMessages(XLGConstants.TIMEDOWN);
        Message obtain = Message.obtain(vpHandler, XLGConstants.TIMEDOWN, millisUntilFinished);
        obtain.sendToTarget();
//		Message message = new Message();
//		message.what = XLGConstants.TIMEDOWN;
//		message.obj = millisUntilFinished;
//		vpHandler.sendMessage(message);
    }

}
